package cn.gailvlun.gll.util;

import android.app.Activity;

import com.umeng.analytics.MobclickAgent;

import cn.gailvlun.gll.net.base.Profile;
import cn.gailvlun.gll.presentation.login.CompleteProfileActivity;
import cn.gailvlun.gll.presentation.login.adapter.LoginType;
import cn.gailvlun.gll.presentation.login.PhoneBindingActivity;
import cn.gailvlun.gll.presentation.main.MainActivity;



public class LoginUtil {

    public static void thirdLoginComplete(Activity activity, Profile profile) {
        ProfileUtil.modify(profile);

        MobclickAgent.onProfileSignIn(String.valueOf(profile.getId()));
        login(activity, profile.isActivated(), true);
    }

    public static void login(Activity activity, Profile profile) {
        
        ProfileUtil.save(profile);

        MobclickAgent.onProfileSignIn(String.valueOf(profile.getId()));
        login(activity, profile.isActivated(), true);
    }

    public static void complete(Activity activity, Profile profile) {
        ProfileUtil.setActivated(profile);
        MobclickAgent.onProfileSignIn(String.valueOf(profile.getId()));
        login(activity, profile.isActivated(), true);
    }

    public static void login(Activity activity, boolean isActivated, boolean isFromLogin) {
        if (isActivated) {
            MainActivity.openActivity(activity, isFromLogin);
        } else {
            CompleteProfileActivity.openActivity(activity);
        }
        activity.finish();
    }

    public static void thirdLogin(Activity activity, Profile profile, LoginType loginType) {
        ProfileUtil.save(profile);
        MobclickAgent.onProfileSignIn(loginType.backEndName, String.valueOf(profile.getId()));
        
        if (profile.getMobile().equals(profile.getUid())) {
            
            PhoneBindingActivity.openActivity(activity);
        } else {
            login(activity, profile.isActivated(), true);
        }
    }
}
